package ch.hoth.java.joocal;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Calendar{
	
	private List<Event2> events;
	private GoogleUser user;
	
	public Calendar(GoogleUser user){
		this.user = user;
		events = new ArrayList<Event2>();	
	}
	
	public void addEvent(Event2 event){
		events.add(event);
	}
	
	public String getCalendarName(){
		return user.getCalendarName();
	}
	
	public List<Event2> getEvents(){
		return events;
	}
	
	public List<Event2> getEvents(Date date){
		List<Event2> dateEvents = new ArrayList<Event2>();
		SimpleDateFormat formatter = new SimpleDateFormat("d-m-y");
		String fDate = formatter.format(date);
		for (Event2 e :events){
			if (fDate.equals(formatter.format(new Date(e.getEvent().getTimes().get(0).getStartTime().getValue())))){
				dateEvents.add(e);
			}
		}
		return dateEvents;
	}
}
